package model

import (
	"fmt"
	"strconv"
)

func GetUserList(username string, realname string, pageNum int, pageSize int) ([]map[string]string, string) {
	var sql = "select * from sys_user where 1=1"
	var sqlCount = "select count(*) as 'total' from sys_user where 1=1"

	if username != "" || realname != "" {
		sql += "where "
	}

	if username != "" {
		sql += " and username like '" + username + "'"
	}

	if realname != "" {
		sql += " and username like '" + username + "'"
	}

	var offset = strconv.Itoa((pageNum - 1) * pageSize)
	var rows = strconv.Itoa(pageSize)
	sql += " limit " + offset + "," + rows

	userList := Orm.Query(sql)
	fmt.Println(userList)
	total := Orm.Query(sqlCount)
	return userList, total[0]["sqlCount"]
}
